package la.bbs558.config;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author: Shanks
 * @date: 2023/12/24 19:46
 * @desc:
 */
@Component
public class CustomIdGenerator implements IdentifierGenerator {

    @Resource
    private Snowflake snowflake;

    @Override
    public Number nextId(Object entity) {
        return snowflake.nextId();
    }

    @Bean
    public Snowflake createSnowflake() {
        return IdUtil.getSnowflake(1, 1);
    }
}
